package com.bw.aop;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAOP {

    @Around("execution( * com.bw.controller.*.*(..) )")
    public Object aop(ProceedingJoinPoint joinPoint) throws Throwable {

        String name = joinPoint.getSignature().getName();
        System.out.println("方法名 " + name);

        Object[] args = joinPoint.getArgs();
       // System.out.println("方法的入参"  + JSON.toJSONString(args, SerializerFeature.IgnoreNonFieldGetter));  // list方法入参有Model  model 不允许被JSON打印
        System.out.println("方法的入参"  + args);  // list方法入参有Model  model 不允许被JSON打印

        long l = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();

        long l2 = System.currentTimeMillis();

        System.out.println("方法的运行时间是 " + (l2-l));
        return proceed;
    }
}
